﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SmartWarehouse.BussinessLogic.Basis;
using SmartWarehouse.Common;
using System.Globalization;
using System.IO;

public partial class PhysicalInventory : SwBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        ClearMessage();
        if (drpOrderBy.SelectedIndex == 0)
        {
            ShowMessage(new SwMessage(SwMessageType.Infomation, "请选择排序方式"));
            return;
        }
        else
        {
            this.lnkDownloadExcel.Visible = true;
        }

        InventoryFacade InvFacade = new InventoryFacade();
        DataTable dtInventory = InvFacade.GetInventoryByOrder(this.drpOrderBy.SelectedValue);

        gvInventory.DataSource = dtInventory;
        gvInventory.DataBind();
    }
    protected void lnkDownloadExcel_Click(object sender, EventArgs e)
    {
        InventoryFacade InvFacade = new InventoryFacade();
        DataTable dtInventory = InvFacade.GetInventoryByOrder(this.drpOrderBy.SelectedValue);
        
        //Change the exported excel appearance
        dtInventory.Columns.Remove("InQty");
        dtInventory.Columns.Remove("outQty");
        dtInventory.Columns["Product_Name"].ColumnName = "产品名称";
        dtInventory.Columns["Cur_Warehouse"].ColumnName = "仓库";
        dtInventory.Columns["Cur_Location"].ColumnName = "仓位";
        dtInventory.Columns["Cur_Bin"].ColumnName = "储位";
        dtInventory.Columns["Qty"].ColumnName = "数量";

        ExcelExporter.Export(this.Response, dtInventory, "PhysicalInventory.xls");
    }
}
